home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 123 / MacAddict_123_2006_11.iso / Software / Utilities / VelaClock 1.9.wdgt / Scripts / Main.js < prev   
Text File  |  2006-08-29  |  71KB  |  2,495 lines

  1. // Copyright 2005-2006, Vela Design Group.  All rights reserved.
  2.  
  3. var placeTimes = new Array();
  4.  
  5. var widgetWidth = 276;
  6. var backsideHeight = 400; //vc16: 365; vc13: 315
  7.  
  8. var currentSelection = null;
  9. var showingInfo = true;
  10. var showAMPM = true;
  11. var showLeadingZeros = false;
  12. var hideSeconds = true;
  13. var useDSTInsteadOfSummer = true;
  14. var showMoonLine = true;
  15. var showChangeInMinutes = true;
  16. var sortByCountry = false;
  17.  
  18. var isShowingFront = true;
  19. //var backsideChanged = false;
  20. var is1043orNewer = true;
  21. var needToCompleteTransition = false;
  22.  
  23.  
  24. //pref keys
  25. var selectionPrefKey = "selection";
  26. var showAMPMPrefKey = "showAMPM";
  27. var showLeadingZerosPrefKey = "showLeadingZeros";
  28. var hideSecondsPrefKey = "hideSeconds";
  29. var useDSTInsteadOfSummerPrefKey = "useDSTInsteadOfSummer";
  30. var showChangeInMinutesPrefKey = "showChangeInMinutes";
  31. var showMoonLinePrefKey = "showMoonLine";
  32. var sortByCountryPrefKey = "sortByCountry";
  33. var regionPrefKey = "region15";
  34. var placePrefKey = "place15";
  35.  
  36. var maxItems = 24;
  37.  
  38.  
  39. function getLocalizedString (key)
  40. {
  41.     try {
  42.         var ret = localizedStrings[key];
  43.         if (ret === undefined)
  44.             ret = key;
  45.         return ret;
  46.     } catch (ex) {}
  47.  
  48.     return key;
  49. }
  50.  
  51. //
  52. //    update functions
  53. //
  54.  
  55. var validMode = true;
  56. var demoMode = true;
  57.  
  58. //pre-fetch images
  59. (new Image()).src = "Images/digTime12_1.png";
  60. (new Image()).src = "Images/digTime12_5.png";
  61. (new Image()).src = "Images/digTime24_1.png";
  62. (new Image()).src = "Images/digTime24_5.png";
  63.  
  64. (new Image()).src = "Images/light1.png";
  65. (new Image()).src = "Images/light2.png";
  66. (new Image()).src = "Images/light3.png";
  67. (new Image()).src = "Images/light4.png";
  68. (new Image()).src = "Images/light5.png";
  69.  
  70. function getEarthLightImage(earthLight)
  71. {        
  72.     var imageSrc;
  73.     
  74.     switch (earthLight) {
  75.         case 1:
  76.             imageSrc = "Images/light1.png";
  77.             break;
  78.         case 2:
  79.             imageSrc = "Images/light2.png";
  80.             break;
  81.         case 3:
  82.             imageSrc = "Images/light3.png";
  83.             break;
  84.         case 4:
  85.             imageSrc = "Images/light4.png";
  86.             break;
  87.         default: //night
  88.             imageSrc = "Images/light5.png";
  89.     }
  90.     
  91.     return imageSrc;
  92. }
  93.  
  94. function updateNow()
  95. {
  96.     if (window.vtMain && validMode)
  97.     //if (window.vtMain && isShowingFront && validMode) //vc14
  98.     {
  99.         
  100.         //alert("  js-updateNow");
  101.  
  102.         var header = document.getElementById('placesHeader');
  103.  
  104.         var dataForAllRows = vtPlace.infoForAllRows();
  105.  
  106.         var count = placeTimes.length;
  107.           for (var index = 0; index < count; ++index)
  108.           {
  109.               try 
  110.               {
  111.                 var placeTimeID =  placeTimes[index];
  112.                 var placeSpan = document.getElementById(placeTimeID+"_place");
  113.                 //position dependent code (firstChild)?
  114.                 
  115.                 placeSpan.firstChild.data = dataForAllRows[index][0];
  116.                 
  117.                 var time24Span = document.getElementById(placeTimeID+"_time24");
  118.                 var time12Span = document.getElementById(placeTimeID+"_time12");
  119.                 var timeAMPMSpan = document.getElementById(placeTimeID+"_timeAMPM");
  120.                 
  121.                 var timeInfo = dataForAllRows[index][1];
  122.                 time24Span.firstChild.data = timeInfo[0];
  123.                 time12Span.firstChild.data = timeInfo[1];
  124.                 timeAMPMSpan.firstChild.data = timeInfo[2];
  125.  
  126.                 var row = header.childNodes[index];
  127.                 
  128.                 var savedEarthLight = row.earthLight;
  129.                 var earthLight = dataForAllRows[index][2];
  130.                 
  131.                 if (earthLight != savedEarthLight) {
  132.                     row.setAttribute ("earthLight", earthLight);
  133.  
  134.                     //set background image for digital time
  135.                     var lightBox = document[placeTimeID+"_light"];
  136.                     lightBox.src = getEarthLightImage(earthLight);
  137.                     
  138.                     if (earthLight == 1 || earthLight == 5)
  139.                         lightBox.setAttribute ("style", "visibility:hidden;");
  140.                     else
  141.                         lightBox.setAttribute ("style", "visibility:visible;");
  142.  
  143.                     //set color of digital time text
  144.                     var digTimeBackground = document[placeTimeID+"_digTimeBack"];
  145.                     if (earthLight == 1) {
  146.                         if (showAMPM)
  147.                             digTimeBackground.src = "Images/digTime12_1.png";
  148.                         else
  149.                             digTimeBackground.src = "Images/digTime24_1.png";
  150.         
  151.                         time24Span.setAttribute ("class", "digTime24");
  152.                         time12Span.setAttribute ("class", "digTime12");
  153.                         timeAMPMSpan.setAttribute ("class", "digTimeAMPM");
  154.                     } else {
  155.                         if (showAMPM)
  156.                             digTimeBackground.src = "Images/digTime12_5.png";
  157.                         else
  158.                             digTimeBackground.src = "Images/digTime24_5.png";
  159.  
  160.                         time24Span.setAttribute ("class", "digTime24 digNight");
  161.                         time12Span.setAttribute ("class", "digTime12 digNight");
  162.                         timeAMPMSpan.setAttribute ("class", "digTimeAMPM digNight");
  163.                     }
  164.                     
  165.                     if (showAMPM)
  166.                         digTimeBackground.setAttribute("style", "left: 177px;");
  167.                     else
  168.                         digTimeBackground.setAttribute("style", "left: 195px;");
  169.                 }
  170.  
  171.             } catch (ex)
  172.             {
  173.                 // don't let one exception lose all the data
  174.             }
  175.         }
  176.  
  177.         updateInfo();
  178.     }
  179. }
  180.  
  181.  
  182. //    Love love love
  183. //    You better hope love is the answer baby
  184. //    I think you better hope it comes before the summer
  185. //    - Jimi Hendrix
  186.  
  187.  
  188. var clockHandHours1 = new Image (13, 46); //(14, 46) (4, 24)
  189. clockHandHours1.src = 'Images/clockHandHours1.png';
  190.  
  191. var clockHandHours2 = new Image (13, 46); //(14, 46) (4, 24)
  192. clockHandHours2.src = 'Images/clockHandHours2.png';
  193.  
  194. var clockHandHours3 = new Image (13, 46); //(14, 46) (4, 24)
  195. clockHandHours3.src = 'Images/clockHandHours3.png';
  196.  
  197. var clockHandHours4 = new Image (13, 46); //(14, 46) (4, 24)
  198. clockHandHours4.src = 'Images/clockHandHours4.png';
  199.  
  200. var clockHandHours5 = new Image (13, 46); //(14, 46) 14, 46
  201. clockHandHours5.src = 'Images/clockHandHours5.png';
  202.  
  203. var clockHandHours = clockHandHours1;
  204.  
  205.  
  206. var clockHandMinutes1 = new Image (13, 46); //(14, 46) (2, 30)
  207. clockHandMinutes1.src = 'Images/clockHandMinutes1.png';
  208. var clockHandMinutes5 = new Image (13, 46); //(14, 46) (2, 30)
  209. clockHandMinutes5.src = 'Images/clockHandMinutes5.png';
  210.  
  211. var clockHandMinutes = clockHandMinutes1;
  212.  
  213. var clockHandSeconds = new Image (13, 46); //(14, 46) (3, 49)
  214. clockHandSeconds.src = 'Images/clockHandSeconds.png';
  215.  
  216. var clockHandsScrew = new Image (13, 46); //(14, 46) (3, 49)
  217. clockHandsScrew.src = 'Images/clockHandsScrew.png';
  218.  
  219. function drawClockHands(handAngles)
  220. {
  221.     //handAngles[0], handAngles[1], handAngles[2]
  222.     //secondsAngle, minutesAngle, hoursAngle
  223.  
  224.     var canvas = document.getElementById("clock-canvas");
  225.     var context = canvas.getContext("2d");
  226.     
  227.     context.clearRect (0, 0, 94, 94);
  228.  
  229.     context.save();
  230.     context.translate (94/2, 94/2);
  231.  
  232.     //minutes
  233.     context.save();
  234.     context.rotate (handAngles[1]);
  235.     context.translate (-7.0, -39.5);
  236.     context.drawImage (clockHandMinutes, 0, 0, 13, 46);
  237.     //vc17
  238.     //context.translate (-7.0, -43.0); // -45.0
  239.     //context.drawImage (clockHandMinutes, 0, 0, 14, 46);
  240.     context.restore();
  241.  
  242.     //hours
  243.     context.save();
  244.     context.rotate (handAngles[2]);    
  245.     context.translate (-6.5, -39.5);
  246.     context.drawImage (clockHandHours, 0, 0, 13, 46);
  247.     //vc17
  248.     //context.translate (-7.0, -40.0);
  249.     //context.drawImage (clockHandHours, 0, 0, 14, 46);
  250.     context.restore();
  251.  
  252.     //seconds
  253.     if (!hideSeconds)
  254.     {
  255.         context.save();
  256.         context.rotate (handAngles[0]);
  257.         context.translate (-7.0, -39.5); // -45.0
  258.         context.drawImage (clockHandSeconds, 0, 0, 13, 46);
  259.         //vc17
  260.         //context.translate (-7.0, -43.0); // -45.0
  261.         //context.drawImage (clockHandSeconds, 0, 0, 14, 46);
  262.         context.restore();
  263.     }
  264.     
  265.     context.translate (-6.5, -39.5);
  266.     context.drawImage (clockHandsScrew, 0, 0, 13, 46);
  267.  
  268.     context.restore();
  269. }
  270.  
  271. //updateSeconds is not called unless the analog clock is showing.
  272. //This is critical to prevent unnecessary use of the processor.
  273. //The plug-in can determine if the analog clock is showing or not.
  274.  
  275. function updateSeconds(handAngles, timeInfo, seconds)
  276. {
  277.     if (window.vtMain) {
  278.         
  279.         if (showingInfo)
  280.         {
  281.             drawClockHands(handAngles);
  282.             document.getElementById("localTimeSeconds").innerText = timeInfo[0];
  283.             if (showAMPM) {
  284.                 document.getElementById("localTime").innerText = timeInfo[2];
  285.                 document.getElementById("localTimeAMPM").innerText = timeInfo[3];
  286.             } else {
  287.                 document.getElementById("localTime").innerText = timeInfo[1];
  288.                 document.getElementById("localTimeAMPM").innerText = "";
  289.             }
  290.         }
  291.     }
  292. }
  293.  
  294. function createRow (rowIndex)
  295. {
  296.     var placeTimeID =  placeTimes[rowIndex];
  297.     
  298.     var row = document.createElement('div');
  299.     
  300.     row.setAttribute ("class", "placeTitle");
  301.     row.setAttribute ("onclick", "clickonrow(event, this);");
  302.  
  303.     //addClock MUST be called before this code (to initialize placeTimes).
  304.     row.setAttribute ("placeTimeID", placeTimeID);
  305.     //alert("createRow: placeTimeID = " + placeTimeID + " " + vtPlace.infoStringForRow(0, rowIndex));
  306.  
  307.     row.setAttribute ("earthLight", "-1");
  308.     
  309.     var flagImage = document.createElement('img');
  310.     flagImage.setAttribute ("class", "flag");
  311.     var flagInfo = vtPlace.flagInfoForRow(rowIndex);
  312.     flagImage.src = flagInfo[0];
  313.     flagImage.setAttribute ("style", "padding-top:" + flagInfo[1]);
  314.     row.appendChild (flagImage);
  315.     
  316.     var placeSpan = document.createElement('span');
  317.     placeSpan.setAttribute ("class", "place");
  318.     placeSpan.setAttribute ("id", placeTimeID + "_place");
  319.     placeSpan.innerText = " ";
  320.     //Amundsen-Scott Station or Dumont-d'Urville Base
  321.     if (placeTimeID == "010" || placeTimeID == "017")
  322.         placeSpan.setAttribute ("style", "font-size:13px;");
  323.     row.appendChild (placeSpan);
  324.     
  325.     var digTimeBgImage = document.createElement('img');
  326.     digTimeBgImage.setAttribute ("class", "digTimeBg");
  327.     digTimeBgImage.setAttribute ("id", placeTimeID + "_digTimeBack");
  328.     digTimeBgImage.setAttribute ("onclick", "clickonTime(event, this);");
  329.     row.appendChild (digTimeBgImage);
  330.     
  331.     var lightImage = document.createElement('img');
  332.     lightImage.setAttribute ("class", "light");
  333.     lightImage.setAttribute ("id", placeTimeID + "_light");
  334.     lightImage.setAttribute ("onclick", "clickonTime(event, this);");
  335.     lightImage.src = getEarthLightImage(2); //twilight is default
  336.     lightImage.setAttribute ("style", "visibility:hidden;"); //hidden is default
  337.     row.appendChild (lightImage);
  338.  
  339.     //time24
  340.     var time24Span = document.createElement('span');
  341.     time24Span.setAttribute ("class", "digTime24");
  342.     time24Span.setAttribute ("id", placeTimeID + "_time24");
  343.     time24Span.setAttribute ("onclick", "clickonTime(event, this);");
  344.     time24Span.innerText = "23:59 PM";
  345.     if (showAMPM)
  346.         time24Span.setAttribute ("style", "display:none;");
  347.     row.appendChild (time24Span);
  348.  
  349.     //time12
  350.     var time12Span = document.createElement('span');
  351.     time12Span.setAttribute ("class", "digTime12");
  352.     time12Span.setAttribute ("id", placeTimeID + "_time12");
  353.     time12Span.setAttribute ("onclick", "clickonTime(event, this);");
  354.     time12Span.innerText = "11:59 PM";
  355.     if (!showAMPM)
  356.         time12Span.setAttribute ("style", "display:none;");
  357.     row.appendChild (time12Span);
  358.     
  359.     //timeAMPM
  360.     var timeAMPMSpan = document.createElement('span');
  361.     timeAMPMSpan.setAttribute ("class", "digTimeAMPM");
  362.     timeAMPMSpan.setAttribute ("id", placeTimeID + "_timeAMPM");
  363.     timeAMPMSpan.setAttribute ("onclick", "clickonTime(event, this);");
  364.     timeAMPMSpan.innerText = "AM";
  365.     if (!showAMPM)
  366.         timeAMPMSpan.setAttribute ("style", "display:none;");
  367.     row.appendChild (timeAMPMSpan);
  368.  
  369.     return row;
  370. }
  371.  
  372. //pre-fetch images
  373. (new Image()).src = "Images/backside1.png";
  374. (new Image()).src = "Images/backside2.png";
  375.  
  376. var curBacksideItem = 0;
  377. //var resizedWhenFlippedOver = false;
  378. var alertWasShowing = false;
  379.  
  380.  
  381. function showbackside(event) {
  382.     var front = document.getElementById("front");
  383.     var back = document.getElementById("back");
  384.  
  385.     var frontIsShorter = calculateWidgetHeight() < backsideHeight;
  386.  
  387.     //curBacksideItem = 1;
  388.     //document.getElementById ('content-backsideMenu').options[curBacksideItem].selected = true;
  389.     changeBacksideContent();
  390.  
  391.     //alert("showbackside: widgetHeight = " + calculateWidgetHeight());
  392.     
  393. /*
  394.     resizedWhenFlippedOver = true;
  395.     if (window.widget)
  396.     {
  397.         widget.prepareForTransition("ToBack");
  398.         //resize after flip
  399.         window.resizeTo (widgetWidth, backsideHeight); //450 323
  400.     }
  401. */
  402.     alertWasShowing = alertIsShowing;
  403.     if (alertWasShowing)
  404.         hideAlert();
  405.  
  406.     if (window.widget) {
  407.         if (frontIsShorter)
  408.             window.resizeTo (widgetWidth, backsideHeight);
  409.         widget.prepareForTransition("ToBack");
  410.     }
  411.     
  412.     /*
  413.     resizedWhenFlippedOver = true;
  414.     if (window.widget)
  415.     {
  416.         if (calculateWidgetHeight() < backsideHeight)
  417.         {
  418.             window.resizeTo (widgetWidth, backsideHeight);
  419.             resizedWhenFlippedOver = true;
  420.         }
  421.         //resizing after the flip sometimes truncates the back!
  422.         widget.prepareForTransition("ToBack");
  423.     }
  424.     */
  425.     
  426.     front.style.display="none";
  427.     
  428.     if (!frontIsShorter && window.widget)
  429.         window.resizeTo (widgetWidth, backsideHeight);
  430.     
  431.     back.style.display="block";
  432.     isShowingFront = false;
  433.     
  434.     updateTitle.innerText = "Software Update";
  435.     document.getElementById('sortText').innerHTML = 'Group by Country/State';
  436.     document.getElementById('timeFormatText').innerHTML = 'Show 24-hour time format';
  437.     document.getElementById('leadingZerosText').innerHTML = 'Show leading zeros time format';
  438.     document.getElementById('hideSecondsText').innerHTML = 'Hide seconds (reduce CPU usage)';
  439.  
  440.     document.getElementById('moonVisText').innerHTML = 'Show moon visibility on Light Level bar';
  441.     document.getElementById('changeInMinutesText').innerHTML = 'Show change in minutes of daylight from previous day (in Light Level pane)';
  442.     
  443.     document.getElementById('extendedHoursPhraseTitle').innerHTML = 'Generic Extended Hours Phrase';
  444.     document.getElementById('dstRadioText').innerHTML = 'Daylight Saving Time';
  445.     document.getElementById('summerRadioText').innerHTML = 'Summer Time';
  446.  
  447.     
  448.     document.getElementById('checkAutoText').innerHTML = 'Check automatically';
  449.     document.getElementById('swUpdateResult').innerHTML = "";
  450.     document.getElementById('swUpdateMessage').innerHTML = "";
  451.     
  452.  
  453.     enableAddButton();
  454.     
  455.     if (window.widget)
  456.         setTimeout('widget.performTransition();', 0);
  457.     
  458.     //backsideChanged = false;
  459.     
  460.     document.removeEventListener("keypress", keyPressed, true);
  461.  
  462.     document.getElementById('fliprollie').style.display = 'none';
  463.  
  464.     event.stopPropagation();
  465.     event.preventDefault();
  466. }
  467.  
  468. function rebuildMaintable()
  469. {
  470.     // fix up widget
  471.     var lastSelected = null;
  472.     
  473.     if (currentSelection != null)
  474.         lastSelected = currentSelection.placeTimeID;
  475.         
  476.     setupMainTable (false);
  477.     
  478.     if (lastSelected != null)
  479.     {
  480.         var count = placeTimes.length;
  481.         var found = false;
  482.         for (var index = 0; index < count; ++index)
  483.         {
  484.             if (placeTimes[index] == lastSelected)
  485.             {
  486.                 found = true;
  487.                 break;
  488.             }
  489.         }
  490.         
  491.         if (!found)
  492.         {
  493.             // the item we have selected is gone. select the first one
  494.             clickonrowimp (document.getElementById('placesHeader').firstChild);
  495.         }
  496.         else
  497.         {
  498.             moveSelectionToPlaceID (lastSelected);
  499.         }
  500.     }
  501.     
  502.     if (window.vtMain)
  503.         vtMain.savePlaceInfo(true);
  504.     
  505.     updateNow();
  506. }
  507.  
  508. function selectDone ()
  509. {
  510.     var front = document.getElementById("front");
  511.     var back = document.getElementById("back");
  512.     
  513.     if (window.widget)
  514.         widget.prepareForTransition("ToFront");
  515.     
  516.     front.style.display="block";
  517.     back.style.display="none";
  518.  
  519.     isShowingFront = true;
  520.     
  521.     if (is1043orNewer)
  522.         needToCompleteTransition = true;
  523.     
  524.     if (window.widget)
  525.         setTimeout ('widget.performTransition();', 0);
  526.         
  527.     //we no longer use the backsideChanged variable.
  528.     //if (backsideChanged)
  529.     //    rebuildMaintable()
  530.     
  531.     setTimeout ('vtMain.refreshClockFace();', 0);
  532.  
  533.     //see transitioncomplete.
  534.     //if (NOT 10.4.3 or newer)
  535.     if (!is1043orNewer) {
  536.         setTimeout("calcWidgetHeightAndResize();", 750); //vc14: 800
  537.         if (alertWasShowing)
  538.             showAlert();
  539.     }
  540.  
  541.     
  542.     //onshow();
  543.     //setTimeout("calcWidgetHeightAndResize();", 0);
  544.     //if (window.widget)
  545.     //    setTimeout ('widget.performTransition();', 0);
  546.     
  547.     /*
  548.     if (resizedWhenFlippedOver)
  549.     {
  550.         calcWidgetHeightAndResize();
  551.         resizedWhenFlippedOver = false;
  552.     }
  553.     */
  554.  
  555.     document.getElementById('swUpdateResult').innerHTML = "";
  556.     document.getElementById('swUpdateMessage').innerHTML = "";
  557.  
  558.     document.addEventListener("keypress", keyPressed, true);
  559. }
  560.  
  561.  
  562. //pre-fetch image
  563. //(new Image()).src = "Images/selection_1.png";
  564. //(new Image()).src = "Images/selection_X.png";
  565. //(new Image()).src = "Images/selection_N.png";
  566.  
  567. function moveSelectionToPlaceID (placeTimeID)
  568. {
  569.     var index;
  570.     var offset = 0; //1
  571.     var count = placeTimes.length;
  572.     for (index=0; index < count; ++index)
  573.     {
  574.         if (placeTimes[index] == placeTimeID)
  575.             break;
  576.     }
  577.     if (index == count)
  578.         index = 0;
  579.     
  580.     if (window.vtMain)
  581.         vtMain2.setSelectedRowForID(placeTimeID);
  582.  
  583.     switch (index)
  584.     {
  585.         case 0:
  586.             selection.src = "Images/selection_1.png";
  587.             offset = -1;
  588.             break;
  589.         case count - 1:
  590.             selection.src = "Images/selection_N.png";
  591.             offset = 1;
  592.             break;
  593.             
  594.         default:
  595.             selection.src = "Images/selection_X.png";
  596.             break;
  597.     }
  598.     
  599.     //the top border is about 6 pixels
  600.     var offsetStr = (25*index + 6 + offset).toString();
  601.     //alert("(" + placeTimeID + " index = " + index + ") off = " + offset + " tot = " + offsetStr);
  602.  
  603.     selection.style.top = offsetStr + "px";
  604.     selection.style.display = "block";
  605.     
  606.     if (!showingInfo) {
  607.         showingInfo = true;
  608.         updateDisplayOptions();
  609.     }
  610.     updateInfo();
  611. }
  612.  
  613. function clickonrowimp (row)
  614. {
  615.     currentSelection = row;
  616.  
  617.     moveSelectionToPlaceID (row.placeTimeID);
  618. }
  619.  
  620.  
  621. //    No reason to get excited, the thief he kindly spoke
  622. //    There are many here among us who feel that life is but a joke
  623. //    But you and I, we've been through that, and this is not our fate
  624. //    So let us not talk falsely now, the hour is getting late
  625. //    - Bob Dylan
  626.  
  627.  
  628. //pre-fetch image
  629. (new Image()).src = "Images/borderBottomNoTabs.png";
  630.  
  631. function updateInfo()
  632. {
  633.     //alert("js-updateInfo: showingInfo = " + showingInfo);
  634.  
  635.     if (currentSelection == null)
  636.     //if (!showingInfo || currentSelection == null) //vc14
  637.         return;
  638.     
  639.     var count = placeTimes.length;
  640.     var found = false;
  641.     for (var index = 0; index < count; ++index)
  642.     {
  643.         if (placeTimes[index] == currentSelection.placeTimeID)
  644.         {
  645.             found = true;
  646.             break;
  647.         }
  648.     }
  649.     
  650.     //alert("js-updateInfo: index = " + index);
  651.  
  652.     if (!found)
  653.     {
  654.         alert("js-updateInfo: !found");
  655.         document.getElementById("currentLight").innerText = "";
  656.         document.getElementById("daylightDuration").innerText = "";
  657.     }
  658.     else
  659.     {
  660.         //sun
  661.         //document.getElementById("currentLightTitle").innerText = vtPlace.infoStringForRow(19, index);
  662.         document.getElementById("currentLight").innerText = vtPlace.infoStringForRow(20, index);
  663.         
  664.         //var earthLight = currentSelection.earthLight;
  665.         var earthLight = vtPlace.earthLightKindForRow(index);
  666.         //alert("updateInfo: earthLight = " + earthLight);
  667.         document.getElementById('lightDot').src = getEarthLightImage(earthLight);
  668.  
  669.         var timeInfo = vtPlace.infoStringListForRow(0, index);
  670.         document.getElementById('timePt-Image').style.left = (timeInfo[3]).toString() + "px";
  671.  
  672.         //
  673.         // update various times
  674.         //
  675.         updateVariousTimesForRow (index);
  676.         
  677.  
  678.         if (showMoonLine)
  679.             document.getElementById('daylight-Image').src = vtPlace.imagePathForRow(2, index);
  680.         else
  681.             document.getElementById('daylight-Image').src = vtPlace.imagePathForRow(1, index);
  682.         
  683.         document.getElementById("daylightDuration").innerText = vtPlace.infoStringForRow(21, index);
  684.  
  685.         var daylightDiv = document.getElementById("daylightDiv");
  686.         if (showChangeInMinutes) {
  687.             daylightDiv.setAttribute("style", "left: 32px;");
  688.             document.getElementById("changeInMinutes").innerText = vtPlace.infoStringForRow(22, index);
  689.         } else {
  690.             daylightDiv.setAttribute("style", "left: 62px;");
  691.             document.getElementById("changeInMinutes").innerText = "";
  692.         }
  693.         
  694.         
  695.         //time
  696.         //drawClockHands
  697.         if (earthLight == 1) {
  698.             document.getElementById('clockFace').src = "Images/clockFaceDay.png";
  699.             clockHandHours = clockHandHours1;
  700.             clockHandMinutes = clockHandMinutes1;
  701.         } else {
  702.             document.getElementById('clockFace').src = "Images/clockFaceNight.png";
  703.             clockHandHours = clockHandHours5;
  704.             clockHandMinutes = clockHandMinutes5;
  705.         }
  706.         
  707.         if (earthLight == 2)
  708.             clockHandHours = clockHandHours2;
  709.         else if (earthLight == 3)
  710.             clockHandHours = clockHandHours3;
  711.         else if (earthLight == 4)
  712.             clockHandHours = clockHandHours4;
  713.         
  714.         
  715.         document.getElementById("localDate").innerText = vtPlace.infoStringForRow(7, index);
  716.         document.getElementById("relativeTime").innerText = vtPlace.infoStringForRow(10, index);
  717.         //document.getElementById("dayOfWeek").innerText = vtPlace.infoStringForRow(8, index);
  718.         
  719.         var utcOffset = vtPlace.infoStringForRow(11, index);
  720.         var tzAbbr = vtPlace.infoStringForRow(12, index);
  721.         document.getElementById("utc_tzAbbr").innerText = tzAbbr + " / " + utcOffset;
  722.         document.getElementById("utcOffset").innerText = utcOffset;
  723.         document.getElementById("tzAbbr").innerText = tzAbbr;
  724.  
  725.         var extendedHoursPhraseIdx = useDSTInsteadOfSummer ? 14 : 15;
  726.         document.getElementById("dst").innerText = vtPlace.infoStringForRow(extendedHoursPhraseIdx, index);
  727.         document.getElementById("season").innerText = vtPlace.infoStringForRow(18, index);
  728.  
  729.         //moon
  730.         var phases = vtPlace.phaseInfoForRow(index);
  731.         
  732.         var prevPhase = phases[0];
  733.         var curPhase = phases[1];
  734.         var nextPhase = phases[2];
  735.  
  736.         //updatePrevNextPhase(true, prevPhase[0]);
  737.         
  738.         //phase times
  739.         if (showAMPM) {
  740.             document.getElementById("prevPhaseTime").innerText = prevPhase[2][1];
  741.             //document.getElementById("curPhaseTime").innerText = "1:11 AM";
  742.             //document.getElementById("curPhaseTime").innerText = curPhase[2][1];
  743.             document.getElementById("nextPhaseTime").innerText = nextPhase[2][1];
  744.         } else {
  745.             document.getElementById("prevPhaseTime").innerText = prevPhase[2][0];
  746.             //document.getElementById("curPhaseTime").innerText = "1:11";
  747.             //document.getElementById("curPhaseTime").innerText = curPhase[2][0];
  748.             document.getElementById("nextPhaseTime").innerText = nextPhase[2][0];
  749.         }
  750.  
  751.         document.getElementById("curPhaseTitle").innerText = curPhase[0][1];
  752.         
  753.         //prev
  754.         document.getElementById("prevPhaseTitle").innerText = prevPhase[0][1];
  755.         document.getElementById("prevPhaseDate").innerText = prevPhase[1][0];
  756.         
  757.         //updatePrevNextPhase(false, nextPhase[0]);
  758.         document.getElementById("nextPhaseTitle").innerText = nextPhase[0][1];
  759.         document.getElementById("nextPhaseDate").innerText = nextPhase[1][0];
  760.         
  761.         document.getElementById('curPhaseDot').src = vtPlace.imagePathForRow(9, index);
  762.         document.getElementById('curPhase-Image').src = vtPlace.imagePathForRow(10, index);
  763.         document.getElementById('prevPhase-Image').src = vtPlace.imagePathForRow(11, index);
  764.         document.getElementById('nextPhase-Image').src = vtPlace.imagePathForRow(12, index);
  765.     }
  766. }
  767.  
  768. //    I am a child, I'll last a while
  769. //    You can't conceive of the pleasure in my smile
  770. //    - Neil Young
  771.  
  772. function clickonrow (event, row)
  773. {
  774.     var oldSelection = currentSelection;
  775.     
  776.     if (currentSelection != null && row == currentSelection)
  777.     {
  778.         document.getElementById("selection").style.display = "none";
  779.         currentSelection = null;
  780.         
  781.         if (window.vtMain)
  782.             vtMain2.setSelectedRowForID("none");
  783.         if (window.widget)
  784.             setPreferenceForKey("none", selectionPrefKey);
  785.     
  786.         setupInfoAnimation (true);
  787.         showingInfo = false;
  788.     }
  789.     else
  790.     {
  791.         clickonrowimp(row);
  792.         
  793.         if (window.widget && oldSelection != currentSelection)
  794.         {
  795.             //write out the selection
  796.             if (window.vtMain)
  797.                 vtMain2.setSelectedRowForID(row.placeTimeID);
  798.             setPreferenceForKey(row.placeTimeID, selectionPrefKey);
  799.         }
  800.         
  801.         if (oldSelection == null)
  802.         {
  803.             showingInfo = true;
  804.             setupInfoAnimation (false);
  805.         }
  806.     }
  807. }
  808.  
  809. function updateVariousTimesForRow (selectionIndex)
  810. {
  811.     var phases = vtPlace.phaseInfoForRow(selectionIndex);
  812.     var prevPhase = phases[0];
  813.     var curPhase = phases[1];
  814.     var nextPhase = phases[2];
  815.  
  816.     //times
  817.     if (showAMPM) {
  818.         document.getElementById("time03").innerText = "3a";
  819.         document.getElementById("time06").innerText = "6a";
  820.         document.getElementById("time09").innerText = "9a";
  821.         document.getElementById("time12").innerText = "12p";
  822.         document.getElementById("time15").innerText = "3p";
  823.         document.getElementById("time18").innerText = "6p";
  824.         document.getElementById("time21").innerText = "9p";
  825.  
  826.         document.getElementById("prevPhaseTime").innerText = prevPhase[2][1];
  827.         //old:
  828.         //document.getElementById("curPhaseTime").innerText = "1:11 AM";
  829.         //document.getElementById("curPhaseTime").innerText = curPhase[2][1];
  830.         document.getElementById("nextPhaseTime").innerText = nextPhase[2][1];
  831.     } else {
  832.         document.getElementById("time03").innerText = "3";
  833.         document.getElementById("time06").innerText = "6";
  834.         document.getElementById("time09").innerText = "9";
  835.         document.getElementById("time12").innerText = "12";
  836.         document.getElementById("time15").innerText = "15";
  837.         document.getElementById("time18").innerText = "18";
  838.         document.getElementById("time21").innerText = "21";
  839.  
  840.         document.getElementById("prevPhaseTime").innerText = prevPhase[2][0];
  841.         //old:
  842.         //document.getElementById("curPhaseTime").innerText = "1:11";
  843.         //document.getElementById("curPhaseTime").innerText = curPhase[2][0];
  844.         document.getElementById("nextPhaseTime").innerText = nextPhase[2][0];
  845.     }
  846.     
  847.     // rise/set info
  848.     var ampmIndex = showAMPM ? 2 : 1;
  849.     var riseSetInfo = vtPlace.infoStringListForRow(1, selectionIndex);
  850.     
  851.     //for (var index = 0; index < placeTimes.length; index++)
  852.     //    alert(index + "riseSetInfo[index]" +  riseSetInfo[index]);
  853.  
  854.     var riseSetIndex;
  855.     for (riseSetIndex = 0; riseSetIndex < 4; riseSetIndex++) {
  856.         document.getElementById ('riseSetTitle'+riseSetIndex).innerText = riseSetInfo[riseSetIndex][0];
  857.         document.getElementById ('riseSetTime'+riseSetIndex).innerText = riseSetInfo[riseSetIndex][ampmIndex];
  858.         document.getElementById ('riseSetAMPM'+riseSetIndex).innerText = showAMPM ? riseSetInfo[riseSetIndex][3] : "";
  859.     }
  860.         
  861.     // twilight info
  862.     var twilightInfo = vtPlace.infoStringListForRow(2, selectionIndex);
  863.     var twilightIndex;
  864.     for (twilightIndex = 0; twilightIndex < 6; twilightIndex++) {
  865.         //alert(twilightIndex + " twi: " + twilightInfo[twilightIndex]);
  866.         document.getElementById ('twilightTitle'+twilightIndex).innerText = twilightInfo[twilightIndex][0];
  867.         document.getElementById ('twilightTime'+twilightIndex).innerText = twilightInfo[twilightIndex][ampmIndex];
  868.         document.getElementById ('twilightAMPM'+twilightIndex).innerText = showAMPM ? twilightInfo[twilightIndex][3] : "";
  869.         var twilightColor;
  870.         switch (twilightInfo[twilightIndex][4]) {
  871.             case 1: //civil
  872.                 twilightColor = "color:#fe8a37;";
  873.                 break;
  874.             case 2: //nautical
  875.                 twilightColor = "color:#10c7b7;";
  876.                 break;
  877.             case 3: //astronomical
  878.                 twilightColor = "color:#0000eb;";
  879.                 break;
  880.             default: //default
  881.                 twilightColor = "color:#fe8a37;";
  882.         }
  883.         document.getElementById('twilightDiv'+twilightIndex).setAttribute ("style", twilightColor);
  884.     }
  885.  
  886. }
  887.  
  888. function clickonTime (event, node)
  889. {
  890.     //var row = node.parentNode;
  891.     //alert("clickonTime: row.placeTimeID = " + row.placeTimeID);
  892.     //alert("clickonTime: event = " + event);
  893.     //alert("clickonTime: window.event = " + window.event);
  894.  
  895.     
  896.     //if (event.altKey)
  897.     //    alert ("clickonTime: option key is down");
  898.     //else
  899.     //    alert ("clickonTime: option key is up");
  900.  
  901.     showAMPM = !showAMPM;
  902.  
  903.     var foundSelection = false;
  904.     var selectionIndex = 0;
  905.     var header = document.getElementById('placesHeader');
  906.  
  907.     for (var index = 0; index < placeTimes.length; ++index)
  908.     {
  909.         var row = header.childNodes[index];                
  910.         var savedEarthLight = row.earthLight;
  911.  
  912.         var placeTimeID = placeTimes[index];
  913.         var time24Span = document.getElementById(placeTimeID+"_time24");
  914.         var time12Span = document.getElementById(placeTimeID+"_time12");
  915.         var timeAMPMSpan = document.getElementById(placeTimeID+"_timeAMPM");
  916.         var digTimeBackground = document[placeTimeID+"_digTimeBack"];
  917.  
  918.         if (showAMPM) {
  919.             if (savedEarthLight == 1)
  920.                 digTimeBackground.src = "Images/digTime12_1.png";
  921.             else
  922.                 digTimeBackground.src = "Images/digTime12_5.png";
  923.             digTimeBackground.setAttribute("style", "left: 177px;");
  924.  
  925.             time24Span.setAttribute ("style", "display:none;");
  926.             time12Span.setAttribute ("style", "display:inline-block;");
  927.             timeAMPMSpan.setAttribute ("style", "display:inline-block;");
  928.         } else {
  929.             if (savedEarthLight == 1)
  930.                 digTimeBackground.src = "Images/digTime24_1.png";
  931.             else
  932.                 digTimeBackground.src = "Images/digTime24_5.png";
  933.             digTimeBackground.setAttribute("style", "left: 195px;");
  934.         
  935.             time24Span.setAttribute ("style", "display:inline-block;");
  936.             time12Span.setAttribute ("style", "display:none;");
  937.             timeAMPMSpan.setAttribute ("style", "display:none;");
  938.         }
  939.  
  940.         //find index of selected row
  941.         if (currentSelection != null && placeTimes[index] == currentSelection.placeTimeID)
  942.         {
  943.             selectionIndex = index;
  944.             foundSelection = true;
  945.         }
  946.     }    
  947.  
  948.  
  949.     // change sun and moon time formats
  950.     if (foundSelection) {
  951.  
  952.         updateVariousTimesForRow (selectionIndex);
  953.         
  954.     }
  955.  
  956.     // set preference
  957.     if (window.widget)
  958.         setPreferenceForKey(showAMPM, showAMPMPrefKey);
  959.     
  960.     //reset checkbox
  961.     document.getElementById('timeFormatCheckbox').checked = !showAMPM;
  962.  
  963.     
  964.     // stop proagation otherwise the clickonrow handler would be called
  965.     event.stopPropagation();
  966.     event.preventDefault();
  967. }
  968.  
  969. //    I'm just a simple guy, I live from day to day. 
  970. //    A ray of sunshine melts my frown and blows my blues away, 
  971. //    Bonham, Page, Plant
  972.  
  973. function clickonLightLevel(event)
  974. {
  975.     showMoonLine = !showMoonLine;
  976.  
  977.     updateInfo();
  978.  
  979.     // set preference
  980.     if (window.widget)
  981.         setPreferenceForKey(showMoonLine, showMoonLinePrefKey);
  982.  
  983.     //reset checkbox
  984.     document.getElementById('moonVisCheckbox').checked = showMoonLine;
  985. }
  986.  
  987. function onshow ()
  988. {
  989.     if (window.vtMain)
  990.         vtMain.onShow();
  991. }
  992.  
  993. function onhide ()
  994. {
  995.     if (window.vtMain)
  996.         vtMain.onHide();
  997. }
  998.  
  999. function transitioncomplete ()
  1000. {
  1001.     //after performTransition
  1002.     if (isShowingFront && needToCompleteTransition)
  1003.     {
  1004.         needToCompleteTransition = false;
  1005.         setTimeout("calcWidgetHeightAndResize();", 0);
  1006.         if (alertWasShowing)
  1007.             showAlert();
  1008.     }
  1009. }
  1010.  
  1011. document.addEventListener("keypress", keyPressed, true);
  1012.  
  1013.  
  1014. function keyPressed(event)
  1015. {
  1016.     //Exit this function if the info area is not showing or there is no selection.
  1017.     if (!showingInfo || currentSelection == null)
  1018.         return;
  1019.     
  1020.     //The up and down arrow keys only function if the info area
  1021.     //    is showing and there is a valid selection.
  1022.     
  1023.  
  1024.     var movedSelection = false;
  1025.     var changedInfo = false;
  1026.     
  1027.     var selection = currentSelection;
  1028.     switch (event.charCode)
  1029.     {
  1030.         case 63232: // up
  1031.             movedSelection = true;
  1032.             selection = selection.previousSibling;
  1033.             if (selection == null)
  1034.             {
  1035.                 selection = document.getElementById('placesHeader').lastChild;
  1036.             }
  1037.             break;
  1038.             
  1039.         case 63233: // down
  1040.             movedSelection = true;
  1041.             selection = selection.nextSibling;
  1042.             if (selection == null)
  1043.             {
  1044.                 selection = document.getElementById('placesHeader').firstChild;
  1045.             }
  1046.             break;
  1047.         
  1048.         //case 63235: // right
  1049.         //case 63234: // left
  1050.  
  1051.         default:
  1052.             movedSelection = false;
  1053.             changedInfo = false;
  1054.             break;
  1055.     }
  1056.     
  1057.     
  1058.     if (movedSelection || changedInfo)
  1059.     {
  1060.         if (movedSelection)
  1061.             clickonrow (event, selection);
  1062.     
  1063.         if (changedInfo)
  1064.             updateInfo();
  1065.     
  1066.         event.stopPropagation();
  1067.         event.preventDefault();
  1068.     }
  1069. }
  1070.  
  1071. function setupMainTable(addPlacesToBackside)
  1072. {
  1073.     var count = placeTimes.length;
  1074.     var container = document.getElementById('placesHeader');
  1075.     removeAllChildren(container);        
  1076.  
  1077.     for (var index=0; index<count; ++index)
  1078.     {
  1079.         var row = createRow (index);
  1080.         container.appendChild (row);
  1081.         if (addPlacesToBackside)
  1082.             addPlace (index);
  1083.     }
  1084.     
  1085.     //set the bottom of table to correct class
  1086.     if (count < 2) count = 2;
  1087.     document.getElementById('tableBottom').setAttribute ("class", (count%2) != 0 ? "tableBottomDark" : "tableBottomLight");
  1088.     
  1089.     // fill in the backgorund
  1090.     container = document.getElementById('tableContainer');
  1091.     removeAllChildren(container);        
  1092.  
  1093.     count = count - 2;
  1094.     var light = true;
  1095.     for (var index = 0; index < count; ++index)
  1096.     {
  1097.         var div = document.createElement ('div');
  1098.         div.setAttribute  ("class", light ? "tableRowLight" : "tableRowDark");
  1099.         container.appendChild (div);
  1100.         light = !light;
  1101.     }
  1102. }
  1103.  
  1104.  
  1105. function addClock(region, place)
  1106. {
  1107.     var placeTimeID = null;
  1108.     
  1109.     if (window.vtMain)
  1110.         placeTimeID = vtPlace.addClock(region, place, sortByCountry);
  1111.     
  1112.     if (placeTimeID != null)
  1113.         placeTimes[placeTimes.length] = placeTimeID;
  1114.     
  1115.     return placeTimeID;
  1116. }
  1117.  
  1118. var curRegionIndex = 4; //America, North
  1119. var curPlaceIndex = 23; //Cupertino (vc14: 20)
  1120. //var curRegionIndex = 1;
  1121. //var curPlaceIndex = 9;
  1122.  
  1123. function setupClocks()
  1124. {
  1125.     // Add default clocks or get clocks from saved preferences.
  1126.     var status = "widget failure";
  1127.     if (window.vtMain)
  1128.         status = vtPlace.infoString(0);
  1129.     document.getElementById("version").innerText = status;
  1130.  
  1131.     
  1132.     if (!validMode)
  1133.         return validMode;
  1134.  
  1135.     var savedPlaces;
  1136.     if (window.vtMain)
  1137.         savedPlaces = vtMain.readPlaceInfo();
  1138.     else
  1139.         savedPlaces = new Array();
  1140.     
  1141.     var placeCount = savedPlaces.length;        
  1142.  
  1143.     if (placeCount > 0) {
  1144.  
  1145.         for (var index = 0; index < placeCount; ++index)
  1146.         {
  1147.             placeTimes[placeTimes.length] = savedPlaces[index];
  1148.         }
  1149.         
  1150.     } else {
  1151.         addClock(4, 23);   //Cupertino (vc14: 20)
  1152.         vtMain.savePlaceInfo(true);
  1153.         //alert("js-setupClocks: savePlaceInfo");
  1154.     }
  1155.     
  1156.     return true;
  1157. }
  1158.  
  1159.  
  1160. var eulaKey = "eula_vc15";
  1161.  
  1162. function selectAgree()
  1163. {
  1164.     document.getElementById('eulaDiv').setAttribute ("style", "display:none;");
  1165.     document.getElementById('front').setAttribute ("style", "display:inline-block;");
  1166.     setupWidget();
  1167.     
  1168.     //Remember agreement (a global pref)
  1169.     if (window.widget)
  1170.         widget.setPreferenceForKey(true, eulaKey);
  1171. }
  1172.  
  1173.  
  1174. var widgetResizedForDialog = false;
  1175. var preDialogHeight;
  1176.  
  1177. function showDialog(showOKButton, showOtherButtons, messageText1, messageText2)
  1178. {
  1179.     if (window.outerHeight < 245) {
  1180.         preDialogHeight = window.outerHeight;
  1181.         window.resizeTo (widgetWidth, 245);
  1182.         widgetResizedForDialog = true;
  1183.     }
  1184.     
  1185.     var buttonAttr;
  1186.     
  1187.     buttonAttr = showOKButton ? "display:block;" : "display:none;";
  1188.     document.getElementById('dialogOKButton').setAttribute ("style", buttonAttr);
  1189.  
  1190.     buttonAttr = showOtherButtons ? "display:block;" : "display:none;";
  1191.     document.getElementById('dialogPurchaseButton').setAttribute ("style", buttonAttr);
  1192.  
  1193.     buttonAttr = showOtherButtons ? "display:block;" : "display:none;";
  1194.     document.getElementById('dialogWebSiteButton').setAttribute ("style", buttonAttr);
  1195.  
  1196.     //alert("*** entered showDialog");
  1197.     document.getElementById("dialogMessage1").innerText = messageText1;
  1198.     document.getElementById("dialogMessage2").innerText = messageText2;
  1199.     document.getElementById('dialogDivContainer').setAttribute ("style", "display:block;");
  1200.     document.getElementById('overlay').setAttribute ("style", "display:block;");
  1201.     //Make flip icon go away if it's visible.
  1202.     //mouseexit(event);
  1203. }
  1204.  
  1205. function controlWidget()
  1206. {
  1207.     //initialize widget plug-in
  1208.     if (window.vtMain)
  1209.     {        
  1210.         // the code is in control!
  1211.         var pluginMode = vtMain.initPlugin(widget.identifier);
  1212.         
  1213.         if (pluginMode == 0)
  1214.             demoMode = false;
  1215.         else if (pluginMode == 1)
  1216.             demoMode = true;
  1217.         else
  1218.             validMode = false;
  1219.     } else {
  1220.         alert("controlWidget: vtMain NOT loaded");
  1221.     }
  1222.  
  1223.     if (demoMode) {
  1224.         
  1225.         //check for eula
  1226.         var agreedToEULA = false;
  1227.         if (window.widget)
  1228.         {
  1229.             var eulaPrefString = widget.preferenceForKey(eulaKey);
  1230.             agreedToEULA = eulaPrefString != null;
  1231.             //alert("eulaPrefString = " + eulaPrefString);
  1232.             //if (eulaPrefString && eulaPrefString.length > 0)
  1233.             //    agreedToEULA = eulaPrefString == eulaValue;
  1234.         }
  1235.  
  1236.         if (agreedToEULA) {
  1237.             setupWidget();
  1238.         } else {
  1239.             document.getElementById('front').setAttribute ("style", "display:none;");
  1240.             document.getElementById('eulaDiv').setAttribute ("style", "display:inline-block;");
  1241.     
  1242.             //Agree button
  1243.             var agreeButton = document.getElementById('agreeButton');
  1244.             createGenericButton (agreeButton, 'Agree', selectAgree, 67);
  1245.         }
  1246.  
  1247.     } else {
  1248.  
  1249.         //set up widget!        
  1250.         document.getElementById('eulaDiv').setAttribute ("style", "display:none;");
  1251.         document.getElementById('front').setAttribute ("style", "display:inline-block;");
  1252.         setupWidget();
  1253.         
  1254.         //Remember agreement (a global pref)
  1255.         if (window.widget)
  1256.             widget.setPreferenceForKey(true, eulaKey);
  1257.     }
  1258. }
  1259.  
  1260. function getPrefs()
  1261. {    
  1262.     showAMPM = getPreferenceForKey(showAMPMPrefKey, false);
  1263.     if (showAMPM == null) {
  1264.         if (window.vtMain)
  1265.             showAMPM = vtMain2.getShowAMPMSystem();
  1266.         else
  1267.             showAMPM = true;
  1268.     }
  1269.     
  1270.     showLeadingZeros = getPreferenceForKey(showLeadingZerosPrefKey, false);
  1271.     if (showLeadingZeros == null) {
  1272.         if (window.vtMain)
  1273.             showLeadingZeros = vtMain.useLeadingZeros();
  1274.         else
  1275.             showLeadingZeros = false;
  1276.     } else {
  1277.         if (window.vtMain)
  1278.             vtMain.setUseLeadingZeros(showLeadingZeros);
  1279.     }
  1280.     
  1281.     hideSeconds = getPreferenceForKey(hideSecondsPrefKey, false);
  1282.     if (hideSeconds == null) {
  1283.         hideSeconds = true;
  1284.     } else {
  1285.         if (window.vtMain)
  1286.             vtMain.setHideSeconds(hideSeconds);
  1287.     }
  1288.     var localTimeSeconds = document.getElementById('localTimeSeconds');
  1289.     if (hideSeconds)
  1290.         localTimeSeconds.setAttribute ("style", "display:none;");
  1291.     else
  1292.         localTimeSeconds.setAttribute ("style", "display:inline-block;");
  1293.  
  1294.  
  1295.     useDSTInsteadOfSummer = getPreferenceForKey(useDSTInsteadOfSummerPrefKey, false);
  1296.     if (useDSTInsteadOfSummer == null) {
  1297.         if (window.vtMain)
  1298.             useDSTInsteadOfSummer = vtMain2.getShowAMPMSystem();
  1299.         else
  1300.             useDSTInsteadOfSummer = true;
  1301.     }
  1302.     
  1303.     
  1304.     showMoonLine = getPreferenceForKey(showMoonLinePrefKey, false);
  1305.     if (showMoonLine == null)
  1306.         showMoonLine = true;
  1307.  
  1308.     showChangeInMinutes = getPreferenceForKey(showChangeInMinutesPrefKey, false);
  1309.     if (showChangeInMinutes == null)
  1310.         showChangeInMinutes = true;
  1311.  
  1312.     sortByCountry = getPreferenceForKey(sortByCountryPrefKey, false);
  1313.     if (sortByCountry == null)
  1314.         sortByCountry = false;
  1315.  
  1316.  
  1317.     //reset checkboxes
  1318.     document.getElementById('sortCheckbox').checked = sortByCountry;
  1319.     document.getElementById('timeFormatCheckbox').checked = !showAMPM;
  1320.     document.getElementById('leadingZerosCheckbox').checked = showLeadingZeros;
  1321.     document.getElementById('hideSecondsCheckbox').checked = hideSeconds;
  1322.     document.getElementById('moonVisCheckbox').checked = showMoonLine;
  1323.     document.getElementById('changeInMinutesCheckbox').checked = showChangeInMinutes;
  1324.     document.getElementById('dstRadio').checked = useDSTInsteadOfSummer;
  1325.     document.getElementById('summerRadio').checked = !useDSTInsteadOfSummer;
  1326.     
  1327.     //curRegionIndex is initialized to 1 (North America)
  1328.     var regionIndexStr = getPreferenceForKey(regionPrefKey, false);
  1329.     if (regionIndexStr != null)
  1330.         curRegionIndex = parseInt(regionIndexStr);
  1331.     
  1332.     //curPlaceIndex is initialized to 23 (Cupertino)
  1333.     var placeIndexStr = getPreferenceForKey(placePrefKey, false);
  1334.     if (placeIndexStr != null)
  1335.         curPlaceIndex = parseInt(placeIndexStr);
  1336.  
  1337.     populateRegionSelect();
  1338.     document.getElementById ('region-dropDownMenu').options[curRegionIndex].selected = true;
  1339.     popuplateCitySelect();
  1340.     document.getElementById ('city-dropDownMenu').options[curPlaceIndex].selected = true;
  1341. }
  1342.  
  1343. function setupWidget()
  1344. {
  1345.     var selectedPlaceTimeID = null;
  1346.     
  1347.     if (window.widget)
  1348.     {
  1349.         
  1350.         //populateBacksideSelect();
  1351.         //document.getElementById ('content-backsideMenu').options[curBacksideItem].selected = true;
  1352.  
  1353.         is1043orNewer = vtMain2.checkFor1043orNewer();
  1354.  
  1355.         //These two elements must be set before setupClocks(). This is mainly
  1356.         //  for the special case of having a newer version then rebooting and 
  1357.         //  not having a network connection.
  1358.         document.getElementById('newVersionText').innerHTML = "";
  1359.         document.getElementById('alertMessage').innerHTML = "";
  1360.         
  1361.         var success = setupClocks();
  1362.  
  1363.         if (!success) {
  1364.             alert("setupClocks failed");
  1365.             return;
  1366.         }
  1367.         
  1368.         try {
  1369.             selectedPlaceTimeID = getPreferenceForKey(selectionPrefKey, false);
  1370.             
  1371.             getPrefs();
  1372.             
  1373.             setupInfoDivs();
  1374.         }
  1375.         catch(ex)
  1376.         {
  1377.             alert("starup error");
  1378.         }
  1379.     }
  1380.  
  1381.  
  1382.     // add all of our places to the widget
  1383.     setupMainTable (true);
  1384.  
  1385.     var header = document.getElementById('placesHeader');
  1386.     currentSelection = header.firstChild;
  1387.     if (selectedPlaceTimeID != null)
  1388.     {
  1389.         if (selectedPlaceTimeID == "none")
  1390.         {
  1391.             document.getElementById("selection").style.display = "none";
  1392.             currentSelection = null;
  1393.             showingInfo = false;
  1394.             document.getElementById('infoAreaContainer').style.height = "0";
  1395.         }
  1396.         else
  1397.         {
  1398.             for (var child = header.firstChild; child != null; child = child.nextSibling)
  1399.             {
  1400.                 if (child.placeTimeID == selectedPlaceTimeID)
  1401.                 {
  1402.                     // no need to do anything if the first item is the one selected.
  1403.                     if (currentSelection != child)
  1404.                     {
  1405.                         clickonrowimp (child);
  1406.                     }
  1407.                 }
  1408.             }
  1409.         }
  1410.     }
  1411.  
  1412.     //adjust position of selected state.
  1413.     if (currentSelection == header.firstChild)
  1414.         clickonrowimp (currentSelection);
  1415.  
  1416.     if (showingInfo) {
  1417.                 
  1418.         //Important
  1419.         updateDisplayOptions();
  1420.         
  1421.         document.getElementById('divSunButton').setAttribute ("style", "display:inline-block;");
  1422.         document.getElementById('divRiseSetButton').setAttribute ("style", "display:inline-block;");
  1423.         document.getElementById('divMoonButton').setAttribute ("style", "display:inline-block;");
  1424.         document.getElementById('divTimeButton').setAttribute ("style", "display:inline-block;");
  1425.  
  1426.         document.getElementById('footer').setAttribute ("style", "background-image:url(Images/borderBottom.png);");
  1427.     }
  1428.     else {
  1429.         document.getElementById('divSunButton').setAttribute ("style", "display:none;");
  1430.         document.getElementById('divRiseSetButton').setAttribute ("style", "display:none;");
  1431.         document.getElementById('divMoonButton').setAttribute ("style", "display:none;");
  1432.         document.getElementById('divTimeButton').setAttribute ("style", "display:none;");
  1433.  
  1434.         document.getElementById('footer').setAttribute ("style", "background-image:url(Images/borderBottomNoTabs.png);");
  1435.     }
  1436.     
  1437.     
  1438.     // backside strings
  1439.     
  1440.     document.getElementById('citiesLabel').innerText = "Cities/Places:";
  1441.     //document.getElementById('demoText').innerHTML = "Demo";
  1442.     
  1443.     //document.getElementById("wTitle").innerText = "VelaClock";
  1444.     document.getElementById("creators").innerText = "Creators";
  1445.     document.getElementById("creator1").innerText = "Jennifer Goshay";
  1446.     document.getElementById("creator2").innerText = "Chuck Soper";
  1447.     document.getElementById("creator3").innerText = "Klaus Strelau";
  1448.     document.getElementById("role1").innerText = "Artist:";
  1449.     document.getElementById("role2").innerText = "Developers:";
  1450.     document.getElementById("role3").innerText = "";
  1451.  
  1452.     document.getElementById("credits").innerText = "Acknowledgments";
  1453.     document.getElementById("source1").innerText = "Astronomy on the Personal Computer";
  1454.     document.getElementById("source1TitleA").innerText = "Authors:";
  1455.     document.getElementById("source1DescA").innerText = "Oliver Montenbruck Thomas Pfleger";
  1456.     document.getElementById("source1TitleB").innerText = "Publisher:";
  1457.     document.getElementById("source1DescB").innerText = "Springer Verlag";
  1458.     document.getElementById("source1Desc").innerText = 'Thorough introduction to the computation of celestial mechanics.';
  1459.     document.getElementById("source1Perm").innerText = "Written permission was obtained from both authors and the publisher.";
  1460.  
  1461.     document.getElementById("source2").innerText = "Photo ¬© UC Regents/Lick Observatory";
  1462.     document.getElementById("source2Desc").innerText = "Full moon photo was taken in the late 1930s with a 36-inch refracting telescope originally built in 1888.";
  1463.     document.getElementById("source2Link").innerText = "www.ucolick.org";
  1464.     document.getElementById("source2Perm").innerText = "Written permission was obtained from Lick Observatory. Unauthorized use prohibited.";
  1465.  
  1466.     document.getElementById("source3").innerText = "tz database";
  1467.     document.getElementById("source3Desc").innerText = "Public-domain time zone database.";
  1468.     
  1469.     document.getElementById("productName").innerText = "VelaClock";
  1470.     document.getElementById("productInfo").innerText = "VelaClock Web Page";
  1471.     document.getElementById("companyName").innerText = "Copyright ¬© 2005-2006 Vela Design Group";
  1472.     document.getElementById("copyright").innerText = "All Rights Reserved";
  1473.  
  1474.     //document.getElementById("regTitle").innerText = "Not Registered";
  1475.  
  1476.  
  1477.     //Add place button
  1478.     var addButton = document.getElementById('addPlace');
  1479.     createGenericButton (addButton, getLocalizedString('Add'), addButtonClicked, 67);
  1480.     enableAddButton();
  1481.     
  1482.     document.getElementById("addHint").innerText = "";
  1483.     
  1484.  
  1485.     //moveUp button
  1486.     var moveUpButton = document.getElementById('moveUp');
  1487.     createGenericButton (moveUpButton, getLocalizedString('‚Üë'), moveUpClicked, 20); //‚Äö√ú√´
  1488.     genericButtonSetEnabled (moveUpButton, false);
  1489.     
  1490.     //moveDown button
  1491.     var moveDownButton = document.getElementById('moveDown');
  1492.     createGenericButton (moveDownButton, getLocalizedString('‚Üì'), moveDownClicked, 20); //‚Äö√ú√¨
  1493.     genericButtonSetEnabled (moveDownButton, false);
  1494.  
  1495.     //Remove place button
  1496.     var removeButton = document.getElementById('removePlace');
  1497.     createGenericButton (removeButton, getLocalizedString('Remove'), removeButtonClicked);
  1498.     genericButtonSetEnabled (removeButton, false);
  1499.     
  1500.     //Other button (for 'Purchase' or 'Send Feedback')
  1501.     var otherButton = document.getElementById('otherButton');
  1502.     var buttonTitle = demoMode ? 'Purchase or Register' : 'Send Feedback'; //use getLocalizedString
  1503.     createGenericButton (otherButton, buttonTitle, purchaseButtonClicked);
  1504.     genericButtonSetEnabled (otherButton, true);
  1505.     
  1506.     //Done button
  1507.     var doneButton = document.getElementById('doneButton');
  1508.     createGenericButton (doneButton, getLocalizedString('Done'), selectDone, 67);
  1509.     
  1510.     //
  1511.     //  Demo Dialog controls
  1512.     //
  1513.     document.getElementById("dialogTitle").innerText = "VelaClock Demo";
  1514.     
  1515.     var dialogOKButton = document.getElementById('dialogOKButton');
  1516.     createButton (dialogOKButton, getLocalizedString('OK'), clickOnOKDialogButton, 66);
  1517.     
  1518.     var dialogPurchaseButton = document.getElementById('dialogPurchaseButton');
  1519.     createButton (dialogPurchaseButton, getLocalizedString('Purchase or Register'), launchPurchaseApp, 136);
  1520.     
  1521.     var dialogWebSiteButton = document.getElementById('dialogWebSiteButton');
  1522.     createButton (dialogWebSiteButton, getLocalizedString('Visit Web Site'), clickLogo, 136);
  1523.  
  1524.     onshow();
  1525.     
  1526.     //CFS
  1527.     updateNow(); //calls updateInfo
  1528.  
  1529.     
  1530.     //if (window.widget && !showingInfo)
  1531.     //if (window.widget && (placeTimes.length != 6 || !showingInfo))
  1532.     //{
  1533.     //    window.resizeTo (widgetWidth, calculateWidgetHeight());
  1534.     //}
  1535.  
  1536.     setTimeout("calcWidgetHeightAndResize();", 0);
  1537.  
  1538.     //This line was added to redraw the clock hands after a reload (cmd-R).
  1539.     if (window.vtMain)
  1540.         setTimeout ('vtMain.refreshClockFace();', 0);
  1541.  
  1542. }
  1543.  
  1544. // add various callbacks
  1545. if (window.widget)
  1546. {
  1547.     widget.onhide = onhide;
  1548.     widget.onshow = onshow;
  1549.     widget.onremove = onremove;
  1550.     widget.ontransitioncomplete = transitioncomplete;
  1551. }
  1552.  
  1553. /*
  1554. var contentList = [
  1555.     {menuItem:'Credits'},
  1556.     {menuItem:'Settings'},
  1557.     {menuItem:'Registration'}
  1558. ];
  1559.  
  1560. function populateBacksideSelect()
  1561. {
  1562.     //alert("populateBacksideSelect: entering");
  1563.  
  1564.     var select = document.getElementById ('content-backsideMenu');
  1565.  
  1566.     //if (select.hasChildNodes())
  1567.     //    return;
  1568.  
  1569.     var menuItemCnt = contentList.length;
  1570.     
  1571.     for (var index = 0; index < menuItemCnt; ++index)
  1572.     {
  1573.         var element = document.createElement("option");
  1574.         element.innerText = contentList[index].menuItem;
  1575.         select.appendChild (element);
  1576.     }
  1577. }
  1578. */
  1579.  
  1580. function showBackCitiesDiv()
  1581. {
  1582.     if (curBacksideItem != 0) {
  1583.         curBacksideItem = 0;
  1584.         changeBacksideContent();
  1585.         //document.getElementById ('content-backsideMenu').options[curBacksideItem].selected = true;
  1586.     }
  1587. }
  1588.  
  1589. function showBackRegDiv()
  1590. {
  1591.     if (curBacksideItem != 1) {
  1592.         curBacksideItem = 1;
  1593.         changeBacksideContent();
  1594.         //document.getElementById ('content-backsideMenu').options[curBacksideItem].selected = true;
  1595.     }
  1596. }
  1597.  
  1598.  
  1599. function showBackHelpDiv()
  1600. {
  1601.     if (curBacksideItem != 2) {
  1602.         curBacksideItem = 2;
  1603.         changeBacksideContent();
  1604.         //document.getElementById ('content-backsideMenu').options[curBacksideItem].selected = true;
  1605.     }
  1606. }
  1607.  
  1608. function showBackCreditsDiv()
  1609. {
  1610.     if (curBacksideItem != 3) {
  1611.         curBacksideItem = 3;
  1612.         changeBacksideContent();
  1613.         //document.getElementById ('content-backsideMenu').options[curBacksideItem].selected = true;
  1614.     }
  1615. }
  1616.  
  1617. function changeBacksideContent()
  1618. {
  1619.     if (curBacksideItem == 0) { //Cities
  1620.         document.getElementById('citiesDiv').setAttribute ("style", "display:inline-block;");
  1621.         document.getElementById('settingsDiv').setAttribute ("style", "display:none;");
  1622.         document.getElementById('helpDiv').setAttribute ("style", "display:none;");
  1623.         document.getElementById('creditsDiv').setAttribute ("style", "display:none;");
  1624.  
  1625.         document.getElementById('backTab1').src = "Images/backTab1.png";
  1626.         document.getElementById('backTab2').src = "Images/backTab2Un.png";
  1627.         document.getElementById('backTab3').src = "Images/backTab3Un.png";
  1628.         document.getElementById('backTab4').src = "Images/backTab4Un.png";
  1629.     }
  1630.     
  1631.     else if (curBacksideItem == 1) { //Settings
  1632.         document.getElementById('citiesDiv').setAttribute ("style", "display:none;");
  1633.         document.getElementById('settingsDiv').setAttribute ("style", "display:inline-block;");
  1634.         document.getElementById('helpDiv').setAttribute ("style", "display:none;");
  1635.         document.getElementById('creditsDiv').setAttribute ("style", "display:none;");
  1636.  
  1637.         document.getElementById('backTab1').src = "Images/backTab1Un.png";
  1638.         document.getElementById('backTab2').src = "Images/backTab2.png";
  1639.         document.getElementById('backTab3').src = "Images/backTab3Un.png";
  1640.         document.getElementById('backTab4').src = "Images/backTab4Un.png";
  1641.     }
  1642.  
  1643.     else if (curBacksideItem == 2) { //Help
  1644.         document.getElementById('citiesDiv').setAttribute ("style", "display:none;");
  1645.         document.getElementById('settingsDiv').setAttribute ("style", "display:none;");
  1646.         document.getElementById('helpDiv').setAttribute ("style", "display:inline-block;");
  1647.         document.getElementById('creditsDiv').setAttribute ("style", "display:none;");
  1648.  
  1649.         document.getElementById('backTab1').src = "Images/backTab1Un.png";
  1650.         document.getElementById('backTab2').src = "Images/backTab2Un.png";
  1651.         document.getElementById('backTab3').src = "Images/backTab3.png";
  1652.         document.getElementById('backTab4').src = "Images/backTab4Un.png";
  1653.     }
  1654.  
  1655.     else { //Credits
  1656.         document.getElementById('citiesDiv').setAttribute ("style", "display:none;");
  1657.         document.getElementById('settingsDiv').setAttribute ("style", "display:none;");
  1658.         document.getElementById('helpDiv').setAttribute ("style", "display:none;");
  1659.         document.getElementById('creditsDiv').setAttribute ("style", "display:inline-block;");
  1660.  
  1661.         document.getElementById('backTab1').src = "Images/backTab1Un.png";
  1662.         document.getElementById('backTab2').src = "Images/backTab2Un.png";
  1663.         document.getElementById('backTab3').src = "Images/backTab3Un.png";
  1664.         document.getElementById('backTab4').src = "Images/backTab4.png";
  1665.     }
  1666.  
  1667. }
  1668.  
  1669. function backsideContentChanged (select)
  1670. {
  1671.     if (curBacksideItem != select.selectedIndex)
  1672.     {
  1673.         curBacksideItem = select.selectedIndex;
  1674.         changeBacksideContent();
  1675.     }
  1676. }
  1677.  
  1678. function populateRegionSelect()
  1679. {
  1680.     //alert("populateRegionSelect: entering");
  1681.  
  1682.     if (window.vtMain) {
  1683.         var regionList = vtMain2.regionList();
  1684.  
  1685.         var select = document.getElementById ('region-dropDownMenu');
  1686.  
  1687.         //if (select.hasChildNodes())
  1688.         //    return;
  1689.  
  1690.         var regionCnt = regionList.length;
  1691.         
  1692.         for (var index = 0; index < regionCnt; ++index)
  1693.         {
  1694.             var element = document.createElement("option");
  1695.             element.innerText = regionList[index];
  1696.             select.appendChild (element);
  1697.         }
  1698.     }
  1699. }
  1700.  
  1701. function popuplateCitySelect()
  1702. {
  1703.     if (window.vtMain) {
  1704.         var placeList = vtMain2.placeListForRegion(curRegionIndex, sortByCountry);
  1705.  
  1706.         var select = document.getElementById ('city-dropDownMenu');
  1707.         while (select.hasChildNodes())
  1708.             select.removeChild(select.firstChild);
  1709.         
  1710.         var placeCnt = placeList.length;
  1711.         
  1712.         for (var index = 0; index < placeCnt; ++index)
  1713.         {
  1714.             var element = document.createElement("option");
  1715.             element.innerText = placeList[index];
  1716.             //if (index == 1)
  1717.             //    element.innerText = placeList[index] + " [$]";
  1718.             //else
  1719.             //    element.innerText = placeList[index];
  1720.             select.appendChild (element);
  1721.         }
  1722.     }
  1723. }
  1724.  
  1725. function enableAddButton(notAvailable)
  1726. {
  1727.     var addButton = document.getElementById('addPlace');
  1728.  
  1729.     if (placeTimes.length == maxItems) {
  1730.         genericButtonSetEnabled (addButton, false);
  1731.         document.getElementById("addHint").innerText = "A maximum of 24 places may be added.";
  1732.         return;
  1733.     }
  1734.  
  1735.     var placeAlreadyExists = true;
  1736.     var addHintText = "";
  1737.     if (window.vtMain) {
  1738.         var addInfoArray = vtPlace.addInfo(curRegionIndex, curPlaceIndex, sortByCountry);
  1739.         placeAlreadyExists = addInfoArray[0];
  1740.         addHintText = addInfoArray[1];
  1741.     }
  1742.     
  1743.     document.getElementById("addHint").innerText = addHintText;
  1744.     genericButtonSetEnabled (addButton, !placeAlreadyExists);
  1745. }
  1746.  
  1747. function regionChanged (select)
  1748. {
  1749.     //alert("regionChanged: entering");
  1750.     if (curRegionIndex != select.selectedIndex)
  1751.     {
  1752.         curRegionIndex = select.selectedIndex;
  1753.         popuplateCitySelect();
  1754.         curPlaceIndex = 0;
  1755.          document.getElementById ('city-dropDownMenu').options[curPlaceIndex].selected = true;
  1756.     
  1757.         enableAddButton();
  1758.         
  1759.         if (window.widget) {
  1760.             setPreferenceForKey(curRegionIndex.toString(), regionPrefKey);
  1761.             setPreferenceForKey(curPlaceIndex.toString(), placePrefKey);
  1762.         }
  1763.     }
  1764. }
  1765.  
  1766. function cityChanged (select)
  1767. {
  1768.     //alert("cityChanged: entering");
  1769.     if (curPlaceIndex != select.selectedIndex)
  1770.     {
  1771.         curPlaceIndex = select.selectedIndex;
  1772.          
  1773.         enableAddButton();
  1774.  
  1775.         if (window.widget) {
  1776.             setPreferenceForKey(curRegionIndex.toString(), regionPrefKey);
  1777.             setPreferenceForKey(curPlaceIndex.toString(), placePrefKey);
  1778.         }
  1779.     }
  1780. }
  1781.  
  1782. var selectedRow=null;
  1783. function clickonbackrow(event, row)
  1784. {
  1785.     var moveUpButton = document.getElementById('moveUp');
  1786.     var moveDownButton = document.getElementById('moveDown');
  1787.  
  1788.     if (placeTimes.length > 1)
  1789.         genericButtonSetEnabled (document.getElementById('removePlace'), true);
  1790.  
  1791.  
  1792.     if (selectedRow == row && event != null && event.metaKey)
  1793.     {
  1794.         row.setAttribute("class", "row");
  1795.         selectedRow = null;
  1796.         genericButtonSetEnabled (moveUpButton, false);    
  1797.         genericButtonSetEnabled (moveDownButton, false);
  1798.         genericButtonSetEnabled (document.getElementById('removePlace'), false);
  1799.     }
  1800.     
  1801.     else if (selectedRow != row)
  1802.     {
  1803.         if (selectedRow != null)
  1804.             selectedRow.setAttribute("class", "row");
  1805.         selectedRow = row;
  1806.         
  1807.         var index;
  1808.         var found = false;
  1809.         var count = placeTimes.length;
  1810.         for (index = 0; index < count; ++index)
  1811.         {
  1812.             if (placeTimes[index] == row.placeTimeID)
  1813.             {
  1814.                 found = true;
  1815.                 break;
  1816.             }
  1817.         }
  1818.  
  1819.         genericButtonSetEnabled (moveUpButton, index != 0);    
  1820.         genericButtonSetEnabled (moveDownButton, index != count-1);
  1821.  
  1822.         //alert("backRow: index = " + index + " placeTimeID = " + row.placeTimeID);
  1823.         
  1824.         row.setAttribute ("class", "row select");
  1825.     }    
  1826.     
  1827.     if (event)
  1828.     {
  1829.         event.stopPropagation();
  1830.         event.preventDefault();
  1831.     }
  1832. }
  1833.  
  1834. var lastValidPlaceTimeID = null;
  1835.  
  1836.  
  1837. function placeAlreadyInSet(placeTimeID)
  1838. {
  1839.     var count = placeTimes.length;
  1840.     
  1841.     for (var index = 0; index < count; ++index)
  1842.     {
  1843.         if (placeTimes[index] == placeTimeID)
  1844.             return index;
  1845.     }
  1846.  
  1847.     return -1;
  1848. }
  1849.  
  1850. function addOrSelectItem ()
  1851. {
  1852.     var index = placeAlreadyInSet(lastValidPlaceTimeID);
  1853.     if (index < 0)
  1854.     {
  1855.         // make sure we have the correct number of items
  1856.         if (placeTimes.length < maxItems)
  1857.         {        
  1858.             index = placeTimes.length;
  1859.             var placeTimeID = addClock(curRegionIndex, curPlaceIndex); 
  1860.             if (placeTimeID != null) {
  1861.                 if (window.vtMain)
  1862.                     vtMain.savePlaceInfo(true);
  1863.                 
  1864.                 var row = addPlace (index);
  1865.                 
  1866.                 //backsideChanged = true;
  1867.                 
  1868.                 clickonbackrow (null, row);
  1869.                 //var innerList = document.getElementById('inner-list');
  1870.                 //innerList.scrollIntoView(false);
  1871.                 
  1872.                 if (placeTimes.length == maxItems)
  1873.                     enableAddButton();
  1874.                 
  1875.                 rebuildMaintable();
  1876.             }
  1877.         }
  1878.     }
  1879.     else
  1880.     {
  1881.         // select the item that is already there.
  1882.         var row = document.getElementById('inner-list').firstChild;
  1883.         for (var i = 0; index < index; ++index)
  1884.             row = row.nextSibling;
  1885.             
  1886.         if (row != null) // just to be safe, should never happen
  1887.         {
  1888.             clickonbackrow (null, row);
  1889.         }
  1890.     }
  1891. }
  1892.  
  1893.  
  1894. function findIndexOfChild (child)
  1895. {
  1896.     var node = child.parentNode;
  1897.     
  1898.     var index = 0;
  1899.     
  1900.     for (node = node.firstChild; node != null; node = node.nextSibling, ++index)
  1901.     {
  1902.         if (node == child)
  1903.             return index;
  1904.     }
  1905.     
  1906.     return -1;
  1907. }
  1908.  
  1909. function removeAllChildren (parent)
  1910. {
  1911.     while (parent.hasChildNodes())
  1912.         parent.removeChild(parent.firstChild);
  1913. }
  1914.  
  1915. function addButtonClicked ()
  1916. {
  1917.     lastValidPlaceTimeID = vtPlace.generatePlaceTimeID(curRegionIndex, curPlaceIndex, sortByCountry);
  1918.     
  1919.     //alert("addButtonClicked: lastValidPlaceTimeID = " + lastValidPlaceTimeID);
  1920.     
  1921.     //CFS: call and fix this function!
  1922.     addOrSelectItem();
  1923.  
  1924.     //scroll to bottom of list
  1925.     if (placeTimes.length > 4) {
  1926.         var list = document.getElementById('list');
  1927.         list.scrollTop = 17 * (placeTimes.length - 4);
  1928.     }
  1929.  
  1930.     enableAddButton();
  1931. }
  1932.  
  1933. function moveUpClicked ()
  1934. {
  1935.     if (selectedRow != null)
  1936.     {
  1937.         var index = findIndexOfChild (selectedRow);
  1938.         if (index <= 1)
  1939.             genericButtonSetEnabled (document.getElementById('moveUp'), false);
  1940.         
  1941.         genericButtonSetEnabled (document.getElementById('moveDown'), true);
  1942.  
  1943.         var parentNode = selectedRow.parentNode;
  1944.         var prevSib = selectedRow.previousSibling;
  1945.         
  1946.         parentNode.insertBefore(selectedRow, prevSib);
  1947.         
  1948.         var idToMove = placeTimes[index];
  1949.         placeTimes[index] = placeTimes[index-1];
  1950.         placeTimes[index-1] = idToMove;
  1951.         
  1952.         //reorder placeTimes array
  1953.         vtPlace.exchangePlaceTimes(index, index-1);
  1954.                 
  1955.         //auto-scroll (disabled for now)
  1956.         //var list = document.getElementById('list');
  1957.         //var topOfRow = (index-1) * 17;
  1958.         //Is row is above visible rows?
  1959.         //if (topOfRow < list.scrollTop)
  1960.         //    list.scrollTop = topOfRow;
  1961.         //Is row is below visible rows?
  1962.         //else if (topOfRow > list.scrollTop + (4*17))
  1963.         //    list.scrollTop = list.scrollTop + (3*17);
  1964.         
  1965.         //backsideChanged = true;
  1966.         rebuildMaintable();
  1967.     }
  1968. }
  1969.  
  1970. function moveDownClicked ()
  1971. {
  1972.     if (selectedRow != null)
  1973.     {
  1974.         var index = findIndexOfChild (selectedRow);
  1975.         if (index >= (placeTimes.length-2))
  1976.             genericButtonSetEnabled (document.getElementById('moveDown'), false);
  1977.  
  1978.         genericButtonSetEnabled (document.getElementById('moveUp'), true);
  1979.  
  1980.         var parentNode = selectedRow.parentNode;
  1981.         var nextSib = selectedRow.nextSibling;
  1982.         
  1983.         parentNode.insertBefore(nextSib, selectedRow);
  1984.         
  1985.         var idToMove = placeTimes[index];
  1986.         placeTimes[index] = placeTimes[index+1];
  1987.         placeTimes[index+1] = idToMove;
  1988.         
  1989.         //reorder placeTimes array
  1990.         vtPlace.exchangePlaceTimes(index, index+1);
  1991.         
  1992.         //auto-scroll (not implemented)
  1993.         //var list = document.getElementById('list');
  1994.  
  1995.         //backsideChanged = true;
  1996.         rebuildMaintable();
  1997.     }
  1998. }
  1999.  
  2000.  
  2001. function removeButtonClicked ()
  2002. {
  2003.     if (selectedRow != null)
  2004.     {
  2005.         var index = findIndexOfChild (selectedRow);
  2006.         var parentNode = selectedRow.parentNode;
  2007.         
  2008.         placeTimes.splice (index, 1);
  2009.  
  2010.         if (window.vtMain) {
  2011.             vtPlace.removePlaceTime(index);
  2012.             vtMain.savePlaceInfo(true);
  2013.             //alert("js-removeButtonClicked: savePlaceInfo");
  2014.         }
  2015.         
  2016.         parentNode.removeChild(selectedRow);
  2017.  
  2018.         selectedRow = null;
  2019.         if (placeTimes.length > 1)
  2020.         {
  2021.             if (index >= placeTimes.length)
  2022.                 index = placeTimes.length-1;
  2023.             
  2024.             var nextSelection = parentNode.firstChild;
  2025.             for (var index=0; index<index;++index)
  2026.                 nextSelection = nextSelection.nextSibling;
  2027.             
  2028.             if (nextSelection != null) {
  2029.                 clickonbackrow (null, nextSelection);
  2030.                 genericButtonSetEnabled (document.getElementById('removePlace'), true);
  2031.             }
  2032.  
  2033.         }
  2034.         else
  2035.         {
  2036.             genericButtonSetEnabled (document.getElementById('removePlace'), false);
  2037.         }
  2038.         
  2039.         enableAddButton();
  2040.         
  2041.         //backsideChanged = true;
  2042.         rebuildMaintable();
  2043.     }
  2044. }
  2045.  
  2046. function setDemoMode(mode)
  2047. {
  2048.     //alert("setDemoMode");
  2049.     
  2050.     demoMode = mode;
  2051.     if (!demoMode) {
  2052.         
  2053.         //show 'registered' dialog
  2054.         document.getElementById("dialogTitle").innerText = "Registration";
  2055.         showDialog(true, false, "VelaClock is registered.", "Thank you.");
  2056.  
  2057.         //update version to show 'registered'
  2058.         document.getElementById("version").innerText = vtPlace.infoString(0);
  2059.         
  2060.         //update the Add button
  2061.         enableAddButton();
  2062.         
  2063.         otherButton = document.getElementById('otherButton');
  2064.         while (otherButton.hasChildNodes())
  2065.             otherButton.removeChild(otherButton.firstChild);
  2066.         createGenericButton (otherButton, 'Send Feedback', purchaseButtonClicked);
  2067.         genericButtonSetEnabled (otherButton, true);
  2068.  
  2069.         //updateNow(); //not necessary
  2070.     }
  2071. }
  2072.  
  2073. function clickonSort(event)
  2074. {
  2075.     sortByCountry = !sortByCountry;
  2076.     
  2077.     popuplateCitySelect();
  2078.  
  2079.     curPlaceIndex = vtMain2.mapPlaceIndex(curRegionIndex, curPlaceIndex, !sortByCountry);
  2080.  
  2081.     //curPlaceIndex = 0; //map placeIndex
  2082.     
  2083.     document.getElementById ('city-dropDownMenu').options[curPlaceIndex].selected = true;
  2084.     enableAddButton();
  2085.  
  2086.  
  2087.     //clickonSort is called when either the checkbox or checkbox title 
  2088.     // (the text next to the checkbox) is clicked. 
  2089.     var sortCheckbox = document.getElementById('sortCheckbox');    
  2090.     
  2091.     //tagName differentiates the checkbox and the checkbox title.
  2092.     if (event.srcElement.tagName != "INPUT")
  2093.         sortCheckbox.checked = !sortCheckbox.checked;
  2094.     
  2095.     // set preference
  2096.     if (window.widget) {
  2097.         setPreferenceForKey(sortByCountry, sortByCountryPrefKey);
  2098.         setPreferenceForKey(curPlaceIndex.toString(), placePrefKey);
  2099.     }
  2100. }
  2101.  
  2102.  
  2103. function clickon24Hour(event)
  2104. {
  2105.     showAMPM = !showAMPM;
  2106.     
  2107.     //clickon24Hour is called when either the checkbox or checkbox title 
  2108.     // (the text next to the checkbox) is clicked. 
  2109.     var timeFormatCheckbox = document.getElementById('timeFormatCheckbox');    
  2110.     
  2111. //    timeFormatCheckbox.checked = showAMPM;
  2112.     
  2113.     //tagName differentiates the checkbox and the checkbox title.
  2114.     if (event.srcElement.tagName != "INPUT")
  2115.         timeFormatCheckbox.checked = !timeFormatCheckbox.checked;
  2116.     
  2117.     // set preference
  2118.     if (window.widget)
  2119.         setPreferenceForKey(showAMPM, showAMPMPrefKey);
  2120.     
  2121.     //backsideChanged = true;
  2122.     rebuildMaintable();
  2123. }
  2124.  
  2125. function clickonLeadingZeros(event)
  2126. {
  2127.     showLeadingZeros = !showLeadingZeros;
  2128.     
  2129.     //clickonLeadingZeros is called when either the checkbox or checkbox title 
  2130.     // (the text next to the checkbox) is clicked. 
  2131.     var leadingZerosCheckbox = document.getElementById('leadingZerosCheckbox');    
  2132.     
  2133.     //tagName differentiates the checkbox and the checkbox title.
  2134.     if (event.srcElement.tagName != "INPUT")
  2135.         leadingZerosCheckbox.checked = !leadingZerosCheckbox.checked;
  2136.     
  2137.     if (window.vtMain)
  2138.         vtMain.setUseLeadingZeros(showLeadingZeros);
  2139.  
  2140.     // set preference
  2141.     if (window.widget)
  2142.         setPreferenceForKey(showLeadingZeros, showLeadingZerosPrefKey);
  2143.     
  2144.     //backsideChanged = true;
  2145.     rebuildMaintable();
  2146. }
  2147.  
  2148.  
  2149. function clickonHideSeconds(event)
  2150. {
  2151.     hideSeconds = !hideSeconds;
  2152.     
  2153.     var localTimeSeconds = document.getElementById('localTimeSeconds');
  2154.     if (hideSeconds)
  2155.         localTimeSeconds.setAttribute ("style", "display:none;");
  2156.     else
  2157.         localTimeSeconds.setAttribute ("style", "display:inline-block;");
  2158.         
  2159.  
  2160.     //clickonLeadingZeros is called when either the checkbox or checkbox title 
  2161.     // (the text next to the checkbox) is clicked. 
  2162.     var hideSecondsCheckbox = document.getElementById('hideSecondsCheckbox');    
  2163.     
  2164.     //tagName differentiates the checkbox and the checkbox title.
  2165.     if (event.srcElement.tagName != "INPUT")
  2166.         hideSecondsCheckbox.checked = !hideSecondsCheckbox.checked;
  2167.     
  2168.     if (window.vtMain)
  2169.         vtMain.setHideSeconds(hideSeconds);
  2170.  
  2171.     // set preference
  2172.     if (window.widget)
  2173.         setPreferenceForKey(hideSeconds, hideSecondsPrefKey);
  2174.     
  2175.     //backsideChanged = true;
  2176. //    rebuildMaintable();
  2177. }
  2178.  
  2179.  
  2180. function clickonDSTRadio(event)
  2181. {
  2182.     useDSTInsteadOfSummer = !useDSTInsteadOfSummer;
  2183.  
  2184.     document.getElementById('dstRadio').checked = true;
  2185.     document.getElementById('summerRadio').checked = false;
  2186.  
  2187.     // set preference
  2188.     if (window.widget)
  2189.         setPreferenceForKey(useDSTInsteadOfSummer, useDSTInsteadOfSummerPrefKey);
  2190. }
  2191.  
  2192. function clickonSummerRadio(event)
  2193. {
  2194.     useDSTInsteadOfSummer = !useDSTInsteadOfSummer;
  2195.  
  2196.     document.getElementById('dstRadio').checked = false;
  2197.     document.getElementById('summerRadio').checked = true;
  2198.  
  2199.     // set preference
  2200.     if (window.widget)
  2201.         setPreferenceForKey(useDSTInsteadOfSummer, useDSTInsteadOfSummerPrefKey);
  2202. }
  2203.  
  2204. function clickonMoonVis(event)
  2205. {
  2206.     showMoonLine = !showMoonLine;
  2207.  
  2208.     //clickonMoonVis is called when either the checkbox or checkbox title 
  2209.     // (the text next to the checkbox) is clicked. 
  2210.     var moonVisCheckbox = document.getElementById('moonVisCheckbox');    
  2211.     
  2212.     //tagName differentiates the checkbox and the checkbox title.
  2213.     if (event.srcElement.tagName != "INPUT")
  2214.         moonVisCheckbox.checked = !moonVisCheckbox.checked;
  2215.     
  2216.     // set preference
  2217.     if (window.widget)
  2218.         setPreferenceForKey(showMoonLine, showMoonLinePrefKey);
  2219.  
  2220.     //backsideChanged = true;
  2221.     rebuildMaintable();
  2222.     
  2223.     //if (window.vtMain)
  2224.     //    vtMain.24Hour(timeFormatCheckbox.checked);
  2225. }
  2226.  
  2227. function clickonChangeInMinutes(event)
  2228. {
  2229.     showChangeInMinutes = !showChangeInMinutes;
  2230.  
  2231.     //clickonMoonVis is called when either the checkbox or checkbox title 
  2232.     // (the text next to the checkbox) is clicked. 
  2233.     var changeInMinutesCheckbox = document.getElementById('changeInMinutesCheckbox');    
  2234.  
  2235.     //tagName differentiates the checkbox and the checkbox title.
  2236.     if (event.srcElement.tagName != "INPUT")
  2237.         changeInMinutesCheckbox.checked = !changeInMinutesCheckbox.checked;
  2238.     
  2239.     // set preference
  2240.     if (window.widget)
  2241.         setPreferenceForKey(showChangeInMinutes, showChangeInMinutesPrefKey);
  2242.  
  2243.     //backsideChanged = true;
  2244.     rebuildMaintable();
  2245.     
  2246. }
  2247.  
  2248. function clickonCheckAuto(event)
  2249. {
  2250.     //clickonCheckAuto is called when either the checkbox or checkbox title 
  2251.     // (the text next to the checkbox) is clicked. 
  2252.     var checkAutoCheckbox = document.getElementById('checkAutoCheckbox');    
  2253.     
  2254.     //tagName differentiates the checkbox and the checkbox title.
  2255.     if (event.srcElement.tagName != "INPUT")
  2256.         checkAutoCheckbox.checked = !checkAutoCheckbox.checked;
  2257.     
  2258.     if (window.vtMain)
  2259.         vtMain.checkAuto(checkAutoCheckbox.checked);
  2260. }
  2261.  
  2262. function clickonCheckNow(event)
  2263. {
  2264.     if (window.vtMain) {
  2265.         var checkNowButton = document.getElementById('checkNowButton');
  2266.         checkNowButton.setAttribute("disabled", "disabled");
  2267.         vtMain.checkNow();
  2268.     }
  2269. }
  2270.  
  2271. var updateLink = null;
  2272.  
  2273. function updateNewVersionText(message, newUpdateLink)
  2274. {
  2275.     document.getElementById('newVersionText').innerHTML = message;
  2276.     updateLink = newUpdateLink;
  2277.     document.getElementById('alertMessage').innerHTML = message;
  2278.     
  2279.     if (message.length > 0) {
  2280.         showAlert();
  2281.     } else {
  2282.         hideAlert();
  2283.         alertWasShowing = false;
  2284.     }
  2285. }
  2286.  
  2287. function updateCheckNowMessage(result, message)
  2288. {
  2289.     //alert("updateCheckNowMessage = " + message);
  2290.     
  2291.     document.getElementById('swUpdateResult').innerHTML = result;
  2292.     document.getElementById('swUpdateMessage').innerHTML = message;
  2293.  
  2294.     var checkNowButton = document.getElementById('checkNowButton');
  2295.     checkNowButton.removeAttribute("disabled");
  2296. }
  2297.  
  2298. var alertIsShowing = false;
  2299.  
  2300. function showAlert()
  2301. {
  2302.     document.getElementById('alertDiv').setAttribute ("style", "display:inline-block;");
  2303.     alertIsShowing = true;
  2304. }
  2305.  
  2306. function hideAlert()
  2307. {
  2308.     document.getElementById('alertDiv').setAttribute ("style", "display:none;");
  2309.     alertIsShowing = false;
  2310. }
  2311.  
  2312.  
  2313. function clickOnOKDialogButton()
  2314. {
  2315.     //make dialog go away
  2316.     document.getElementById('dialogDivContainer').setAttribute ("style", "display:none;");
  2317.     document.getElementById('overlay').setAttribute ("style", "display:none;");
  2318.  
  2319.     //resize widget, if necessary
  2320.     if (widgetResizedForDialog) {
  2321.         window.resizeTo (widgetWidth, preDialogHeight);
  2322.         widgetResizedForDialog = false;
  2323.     }
  2324. }
  2325.  
  2326. function launchPurchaseApp()
  2327. {
  2328.     if (event.shiftKey) {
  2329.         //Use widget.openApplication() if shift key held down.
  2330.         widget.openApplication('com.veladg.VelaReg');
  2331.     } else {
  2332.         var documentPath = document.URL;
  2333.         var pathComponents = documentPath.split("/");
  2334.         var docName = pathComponents[pathComponents.length - 1];
  2335.         var velaRegPath = documentPath.substring(0, (documentPath.length - docName.length)) + "VelaReg.app";
  2336.         //alert("velaRegPath = " + velaRegPath);
  2337.         widget.openURL(velaRegPath);
  2338.         //widget.system("/usr/bin/open " + velaRegPath, null);
  2339.     }
  2340.  
  2341.     //Command key: event.ctrlKey
  2342.     //option key: event.altKey
  2343. }
  2344.  
  2345. function purchaseButtonClicked()
  2346. {
  2347.     //alert("purchaseButtonClicked");
  2348.     if (demoMode) {
  2349.         launchPurchaseApp();
  2350.     } else {
  2351.         widget.openURL("http://www.veladg.com/feedback.html?p=VelaClock");
  2352.     }
  2353. }
  2354.  
  2355. function addPlace (index)
  2356. {
  2357.     var innerList = document.getElementById('inner-list');
  2358.     
  2359.     var row = document.createElement('div');
  2360.     row.setAttribute("class", "row");
  2361.     row.setAttribute("onclick", "clickonbackrow(event, this);");
  2362.     
  2363.     var span = document.createElement('span');
  2364.     span.setAttribute ("class", "placesColumn");
  2365.     if (index < 0) {
  2366.         span.innerText = "unknown";
  2367.     } else {
  2368.         span.innerText = vtPlace.infoStringForRow(0, index);
  2369.         row.setAttribute ("placeTimeID", placeTimes[index]);
  2370.     }
  2371.     row.appendChild(span);
  2372.     
  2373.     innerList.appendChild(row);
  2374.     
  2375.     return row;
  2376. }
  2377.  
  2378. function clickLickObs(event)
  2379. {
  2380.     if (widget)
  2381.         widget.openURL("http://www.ucolick.org/");
  2382. }
  2383.  
  2384. function clickLogo()
  2385. {
  2386.     if (widget) {
  2387.         if (demoMode)
  2388.             widget.openURL("http://www.veladg.com/velaclockDemo.html");
  2389.         else
  2390.             widget.openURL("http://www.veladg.com/velaclock.html");
  2391.     }
  2392. }
  2393.  
  2394. function clickNewVersion(event)
  2395. {
  2396.     if (widget && updateLink != null)
  2397.         widget.openURL(updateLink);
  2398. }
  2399.  
  2400. function calcWidgetHeightAndResize()
  2401. {
  2402.     var height = calculateWidgetHeight();
  2403.     if (window.widget)
  2404.         window.resizeTo(widgetWidth, height);
  2405. }
  2406.  
  2407. function calculateWidgetHeight()
  2408. {
  2409.     var height = 31 + // 34 row 1 (table top)
  2410.                  28 + // 29 row N (table bottom)
  2411.                  30;  // 24 28 35 footer
  2412.     
  2413.     var numberOfRows = placeTimes.length - 2;
  2414.     
  2415.     if (numberOfRows > 0)
  2416.         height += (numberOfRows * 25); // 25 row height
  2417.     
  2418.     var infoHeight = 0; //this used to be global and set to 99.
  2419.  
  2420.     if (showingInfo) {
  2421.         infoHeight += infoAreaTopHeight;    //infoBackTop.png
  2422.         infoHeight += infoAreaBottomHeight; //infoBackBottom.png
  2423.         infoHeight += 10; //5 taller borderBottom (shorter borderBottomNoTabs)
  2424.         //height += infoHeight;
  2425.  
  2426.         var index;
  2427.         var count = infoDivs.length;
  2428.         for (index = 0; index < count; ++index)
  2429.         {
  2430.             var subInfoDiv = infoDivs[index];
  2431.             if (subInfoDiv.showing) {
  2432.                 infoHeight += subInfoDiv.fullHeight ? subInfoDiv.maxHeight : subInfoDiv.minHeight;
  2433.                 infoHeight += infoDivBottomHeight; //used to assign to height
  2434.             }
  2435.             
  2436.             //Or, just calculate the DIV height?
  2437.             //var divElement = document.getElementById(infoDivs[index].id);
  2438.             //infoHeight += parseInt(divElement.style.height, 10);
  2439.         }
  2440.         height += infoHeight;
  2441.     }
  2442.         
  2443.     //alert("widgetHeight = " + height + "; infoHeight = " + infoHeight + "; rows = " + numberOfRows);
  2444.     //var divElement = document.getElementById('infoAreaContainer');
  2445.     //alert("  infoHeight Div = " + divElement.style.height);
  2446.  
  2447.     return height;
  2448. }
  2449.  
  2450. function onremove ()
  2451. {
  2452.     if (window.vtMain)
  2453.         vtMain.onRemove();
  2454.  
  2455.     // remove all the pref keys here
  2456.     if (window.widget) {
  2457.         setPreferenceForKey(null, selectionPrefKey);
  2458.         setPreferenceForKey(null, showAMPMPrefKey);
  2459.         setPreferenceForKey(null, showLeadingZerosPrefKey);
  2460.         setPreferenceForKey(null, hideSecondsPrefKey);
  2461.         setPreferenceForKey(null, useDSTInsteadOfSummerPrefKey);
  2462.         setPreferenceForKey(null, showMoonLinePrefKey);
  2463.         setPreferenceForKey(null, showChangeInMinutesPrefKey);
  2464.         setPreferenceForKey(null, sortByCountryPrefKey);
  2465.         setPreferenceForKey(null, regionPrefKey);
  2466.         setPreferenceForKey(null, placePrefKey);
  2467.     }
  2468. }
  2469.  
  2470. function createKey (key)
  2471. {
  2472.     return widget.identifier + "-" + key;
  2473. }
  2474.  
  2475. function setPreferenceForKey(pref, key)
  2476. {
  2477.     //set pref for widget instance
  2478.     widget.setPreferenceForKey(pref, createKey(key));
  2479.     
  2480.     //consider setting global pref
  2481.     //widget.setPreferenceForKey(pref, key);
  2482. }
  2483.  
  2484. function getPreferenceForKey (key, global)
  2485. {
  2486.     //get pref for widget instance
  2487.     var pref = widget.preferenceForKey(createKey(key));
  2488.     
  2489.     //consider getting global pref
  2490.     //if (pref == null && global)
  2491.     //    pref = widget.preferenceForKey(key);
  2492.     
  2493.     return pref;
  2494. }
  2495.